/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/119
   @Language: C++
   @Datetime: 20-08-13 15:07
   */
// floyd, time O(V^3)

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int v, e, s, t, a, b, c; // vertex edge, start -> target
	scanf("%d %d %d %d", &v, &e, &s, &t);
	vector<vector<int> > edges(v+1, vector<int>(v+1, INT_MAX));
	//vector<vector<int> > path(v+1, vector<int>(v+1));
	//for(int i=0; i++<v; )
	//	for(int j=0; j++<v;)
	//		path[i][j] = j;
	for(int i=0; i++<e; ) {
		scanf("%d %d %d", &a, &b, &c); // a->b, cost
		edges[a][b]=edges[b][a]=c;
	}
	for(int k=0; k++<v;) {
		for(int i=0; i++<v;) {
			for(int j=0; j++<v;) {
				if (edges[i][k]==INT_MAX || edges[k][j]==INT_MAX) continue;
				if (edges[i][k]+edges[k][j]>=edges[i][j]) continue;
				edges[i][j] = edges[i][k]+edges[k][j];
				//path[i][j] = path[i][k];
			}
		}
	}
	/* shortest path s -> ... -> t
	printf("[%d -> %d]=%d : %d", s, t, edges[s][t], s);
	for(int k=path[s][t]; k!=t; k=path[k][t])
		printf(" -> %d", k);
	printf(" -> %d\n", t);
	*/
	printf("%d\n", edges[s][t]);
	return 0;
}
